package com.example.SocialApplication.social.vk.service;

import android.os.AsyncTask;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;

import java.io.IOException;

public class GetVkUserAvatar extends AsyncTask<String, Void, String> {

    @Override
    protected String doInBackground(String... params) {
        HttpClient client = new DefaultHttpClient();
        HttpGet httpRequest = new HttpGet(params[0]);

        String responseText = null;
        try {
            HttpResponse response = client.execute(httpRequest);
            HttpEntity entity = response.getEntity();
            responseText = EntityUtils.toString(entity);
        } catch (IOException e) {
            e.printStackTrace();
        }

        return responseText;

//        Log.d("aaa", responseText);
//        User user = null;
//        try {
//            JSONArray array = new JSONObject(responseText).getJSONArray("response");
//            JSONObject jObj = array.getJSONObject(0);
//
//            user = new User();
//            user.setId(jObj.getString("uid"));
//            user.setFirstName(jObj.getString("first_name"));
//            user.setLastName(jObj.getString("last_name"));
//
//            try {
//                InputStream is = (InputStream) new URL(jObj.getString("photo")).getContent();
//                user.setPhoto(BitmapFactory.decodeStream(is));
//            } catch (Exception e) {
//                e.printStackTrace();
//            }
//        } catch (Exception e) {
//            Log.i("Exception1 is Here>> ", e.toString());
//            e.printStackTrace();
//        }
//
//        return user;
    }
}
